﻿using System;
using System.IO;
using System.Diagnostics;
using CommandLine;
using CommandLine.Text;

namespace SPSource2010
{
    class Program
    {
        private static readonly HeadingInfo _headingInfo = new HeadingInfo("SPSource2010", "2.0.0.0");

        static void Main(string[] args)
        {
            Debugger.Launch();
            try
            {
                var options = new Options();
                //ICommandLineParser parser = new CommandLineParser();
                //if (parser.ParseArguments(args, options, Console.Error))
                //{
                    string path = Environment.CurrentDirectory;
                    var currentDirectory = new DirectoryInfo(Environment.CurrentDirectory);

                    var spSource = new SPSource2010();
                    spSource.DesignSiteUrl = "http://lafarge2010:4444";// options.DesignSite;
                    spSource.OverrideFeatureDirectoryCheck = true;// (options.OverrideFeatureDirectoryCheck == "1" ? true : false);
                    spSource.RootProjDir = currentDirectory;
                    spSource.Execute();

                    Utility.WriteMessage("SPSource2010 Completed", "Completed");
                //}
                //else
                //{
                //    Environment.Exit(1);
                //}
            }
            catch (Exception ex)
            {
                Utility.WriteMessage("An exception occured while running SPSource:" + ex.Message, "Exception occured");
            }
        }

        private sealed class Options
        {
            [Option("d", "DesignSite",
                    Required = true,
                    HelpText = "Design site used to reverse engineer artefacts.")]
            public string DesignSite = "http://lafarge2010:4444";//String.Empty;
            [Option("o", "OverrideFeatureDirectoryCheck",
                    Required = false,
                    HelpText = "Override check for features directory (1|0)")]
            public string OverrideFeatureDirectoryCheck = true.ToString();

            [HelpOption(HelpText = "Display this help screen.")]
            public string GetUsage()
            {
                HelpText help = new HelpText(Program._headingInfo);
                help.Copyright = new CopyrightInfo("@Jthake & @RichFinn", 2008, 2009);
                help.AddPreOptionsLine("Usage: SPSource2010 -d http://server/devsite");
                help.AddPreOptionsLine("Usage: SPSource2010 --DesignSite http://server/devsite");
                help.AddPreOptionsLine("Usage: SPSource2010 --DesignSite http://server/devsite --OverrideFeatureDirectoryCheck true");
                help.AddOptions(this);
                return help;
            }
        }

    }
}
